package com.honey.compilation.sql;

import java.util.ArrayList;
import java.util.List;

import com.honey.core.builder.CharacterBuilder;
import com.honey.core.builder.CharacterBuilderFactory;
import com.honey.core.compiler.IndentSpace;

/**
 * 字符串
 * @author Administrator
 *
 */
public class StringScript implements SqlScript{

	private List<String> strings;
	
	/**
	 * 构造函数
	 */
	public StringScript(){
		strings =new ArrayList<String>();
	}
	
	/**
	 * 构造函数
	 */
	public StringScript(String ...strs){
		strings =new ArrayList<String>();
		addString(strs);
	}

	/**
	 * 
	 * @param strs
	 * @return
	 */
	public StringScript addString(String ...strs){
		for(String str : strs ){
			if(str != null)
				strings.add(str);
		}
		return this;
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.honey.core.dom.CompilationElement#compiledContent(int)
	 */
	@Override
	public CharacterBuilder compiledContent(int indentLevel ){
		CharacterBuilder answer = CharacterBuilderFactory.createC16StringBuilder();
		
		boolean comma = false;
		for(String str : strings ){
			if (comma)IndentSpace.newLine(answer); else comma = true;
			IndentSpace.spaceIndent(answer, indentLevel);
			answer.append(str);
		}
		
		return answer;
	}
}
